﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Common.Master" AutoEventWireup="true" CodeBehind="SingleWellTree.aspx.cs" Inherits="Web.Views.SingleWellManage.SingleWellTree" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="../../zTree3.4/css/zTreeStyle/zTreeStyle.css" rel="stylesheet"
        type="text/css" />
<script src="../../zTree3.4/jquery.ztree.all-3.4.js" type="text/javascript"></script>
  <%--<script type="text/javascript">
      $(function () {
          //加载公司通讯录Tree
          var timestamp = new Date().getTime();
          $('#treeArchiveMenu').tree({
              method: "get",
              lines: true,
              idFiled: "id",
              textFiled: "text",
              parentField: "pid",
              cascadeCheck: false,
              url: "SingleWellLazyTreeHandler.ashx?archivemenu=yes&timestamp=" + timestamp + "",
              onBeforeExpand: function (node, param) {
                  //事件触发时，默认会在该url后面加上id=value 信息发送到服务器
                  $('#treeArchiveMenu').tree('options').url = "SingleWellLazyTreeHandler.ashx?&timespan="+ Math.random();
              },
              onLoadSuccess: function (node, data) {
                  window.parent.document.getElementById('Iframe1').src = "../SystemLogin/loadingpage.aspx?Menu_URL=../SingleWellManage/SingleWellTotalList.aspx?wellType=1";
              },
              onSelect: function (node) {
                  //if ($('#treeArchiveMenu').tree('isLeaf', node.target)) {
                      window.parent.document.getElementById('Iframe1').src = "../SystemLogin/loadingpage.aspx?Menu_URL=../SingleWellManage/SingleWellTotalList.aspx?wellType=" + node.id;
                  //}
              }
          });
      });
  </script>--%>
  <script type="text/javascript">

  (function () {
      //zTree设置
      var setting,
      //时间戳
           timestamp = new Date().getTime(),
      //数据过滤方法
            dataFilter,
      //zTree节点勾选回调事件
            zTreeNode_onCheck;
      //定义联系人数组
      var linkManList = [];
      //数据过滤,修改或去掉无效数据(childNodes为服务器返回数据)
      dataFilter = function (treeId, parentNode, childNodes) {
          var filterNodes = [];

          $.each(childNodes, function (index, node) {
              //过滤节点pid为空
              if (node !== undefined && node.pid !== undefined && node.pid !== null || node.pid !== "") {
                  filterNodes.push(node);
              }
          });
          $.each(filterNodes, function (index, node) {
              //不显示复选框
              if (node !== undefined && node.showCbx !== undefined && !node.showCbx) {
                  node.nocheck = "true";
              }
              //子节点的数据显示 +
              if (node !== undefined && node.state !== undefined && node.state === "open") {
                  node.open = true;
              }
              else {
                  node.isParent = true;
              }
          });
          return filterNodes;
      }

      zTreeNode_onClick = function (event, treeId, treeNode) {
          //          if (treeNode.isParent == false)
          //          {
          window.parent.document.getElementById('Iframe1').src = "../SystemLogin/loadingpage.aspx?Menu_URL=../SingleWellManage/SingleWellTotalList.aspx?wellType=" + treeNode.id;
          //          }
      }

      function ajaxGetNodes(treeNode, reloadType) {
          var zTree = $.fn.zTree.getZTreeObj("treeArchiveMenu");
          if (reloadType == "refresh") {
              treeNode.icon = "../../zTree3.4/css/zTreeStyle/img/loading.gif";
              zTree.updateNode(treeNode);
          }
          zTree.reAsyncChildNodes(treeNode, reloadType, true);
      }

      function beforeExpand(treeId, treeNode) {
          if (!treeNode.isAjaxing) {
              startTime = new Date();
              treeNode.times = 1;
              ajaxGetNodes(treeNode, "refresh");
              return true;
          } else {
              alert("Downloading data, Please wait to expand node...");
              return false;
          }
      }
      function onAsyncSuccess(event, treeId, treeNode, msg) {
          if (!msg || msg.length == 0) {
              return;
          }
          var zTree = $.fn.zTree.getZTreeObj("treeArchiveMenu"),
			totalCount = treeNode.count;
          if (treeNode.children.length < totalCount) {
              setTimeout(function () { ajaxGetNodes(treeNode); }, perTime);
          } else {
              treeNode.icon = "";
              zTree.updateNode(treeNode);
              zTree.selectNode(treeNode.children[0]);
              endTime = new Date();
              var usedTime = (endTime.getTime() - startTime.getTime()) / 1000;
              className = (className === "dark" ? "" : "dark");
          }
      }

      function geturl (treeId, treeNode) {
          var param = "&id=" + treeNode.id;
          return "SingleWellLazyTreeHandler.ashx?archivemenu=yes&timestamp=" + timestamp + param;
      }

      setting = {
          async: {
              enable: true,
              url: geturl,
              //autoParam: ["id", "id=pid", "text=n", "level=lv"],
              dataFilter: dataFilter
          },
          check: {
              enable: false,
              chkStyle: "checkbox",
              chkboxType: { "Y": "", "N": "" }
          },
          data: {
              key: {
                  name: "text"
              },
              simpleData: {
                  enable: true,
                  idKey: "id",
                  pIdKey: "pid",
                  rootPId: 0
              }
          },
          callback: {
              onClick: zTreeNode_onClick,
              beforeExpand: beforeExpand,
              onAsyncSuccess: onAsyncSuccess
              //                       onAsyncError: onAsyncError,
              //                       onCollapse: onCollapse,
          }
      };

      $(function () {

          $(".btn").bind("click", function () {
              var parm = $("#txtsearch").val();
              if (parm.length == 0) {
                  alert("请输入查询条件。");
                  return;
              }
              var url = "SingleWellLazyTreeHandler.ashx?archivemenu=yes&param=" + encodeURIComponent(parm) + "&timestamp=" + timestamp + "";
              //先用ajax取数据，判断数据是否过大
              $.ajax({
                  url: url,
                  contentType: "application/x-www-form-urlencoded",
                  success: function (result) {
                      //code为1，数据有效
                      if (result.length <= 3000) {
                          //                          setting.async.url = url;
                          var nodes = dataFilter("", "", result);
                          $.fn.zTree.init($("#treeArchiveMenu"), setting, nodes);
                      }
                      else {
                          alert("数据传输量过大，已经自动阻止！为了提高体验速度，请精确查询条件。");
                      }
                  }
              });
          });

          $.ajax({
              url: "SingleWellLazyTreeHandler.ashx?archivemenu=yes&id=-1&timestamp=" + Math.random(),
              contentType: "application/x-www-form-urlencoded",
              success: function (result) {
                  //code为1，数据有效
                  if (result.length <= 3000) {
                      //                          setting.async.url = url;
                      var nodes = dataFilter("", "", result);
                      $.fn.zTree.init($("#treeArchiveMenu"), setting, nodes);
                  }
                  else {
                      alert("数据传输量过大，已经自动阻止！为了提高体验速度，请精确查询条件。");
                  }
              }
          });
      });
  })();
  </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<p><span class="require_info">*</span>由于单井编目数据量很大，请输入查询条件进行筛选。</p>
<p><span class="require_info">*</span>输入编目名称进行模糊查询</p>
<input type="text" id="txtsearch"  style="width:150px" title='输入编目名称进行模糊查询'/><input type="button" class="btn" value="查询" />
    <ul id="treeArchiveMenu" class="ztree"></ul>
</asp:Content>
